<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <script src="utils.js"></script>
    <script>
        window.onload = function(){
            var canvas = document.getElementById('canvas'),
                context = canvas.getContext('2d'),
                mouse = utils.captureMouse(canvas)

            function onMouseMove(){
                context.lineTo(mouse.x, mouse.y)
                context.stroke()
            }

            canvas.addEventListener('mousedown', function(){
                context.beginPath()
                context.moveTo(mouse.x, mouse.y)
                canvas.addEventListener('mousemove', onMouseMove)
            })

            canvas.addEventListener('mouseup', function(){
                canvas.removeEventListener('mousemove', onMouseMove)
            })
        }
    </script>
</body>
</html>